package manage;

import login.User;
import login.sellers;
import login.vegetableList;

import java.time.LocalDate;

public class sellerSystem extends Admin {


    public void showSlr(String uid){

        System.out.println(u.findByID(uid));
    }

    //修改店铺名称简介

    public void setName(String uid) {
        System.out.println("请输入您的店铺名称:");
        u.findByID(uid).setUsername(sc.next());
        System.out.println("请输入您的店铺简介:");
        u.findByID(uid).setJianjie(sc.next());
        System.out.println("您的店铺信息：");
        System.out.println(u.findByID(uid));
    }

    //在自己的订单中发放抵用券
    public void pushDiscount(String uid) {

        System.out.println(o.findBySlr(uid));
        System.out.println("请输入您要发放的用户id 和金额，用回车隔开：");
        u.findByID(sc.next()).setYouhuiquan(Double.parseDouble(sc.next()));
        //设定用户拿到的优惠券金额
    }

    //查看自己的订单
    public void findOrder(String uid) {
        System.out.println(o.findBySlr(uid));
        System.out.println("您总共处理了"+o.findBySlr(uid).size()+"张订单");;
    }

    //显示菜品
    public void showDishes(String uid)
    {
        System.out.println(d.findBySlr(uid));
    }

    //添加菜品
    public void addDish() {
        System.out.println("请输入您要添加的菜品：ps.格式：菜品ID/菜品名/菜品类型/单价/总数量");
        String dID = sc.next();
        String[] info = toString().split("/");

        if (info.length < 4) {
            System.out.println("输入失败！请重新输入！");
            addDish();
        } else {
            LocalDate dtime = LocalDate.now();//获取现在
            vegetableList od = new vegetableList(info[0], info[1], info[2], Double.parseDouble(info[3]), Integer.parseInt(info[4]));
            d.insert(od);
            System.out.println("添加菜品成功！");
        }
    }


    //根据菜品id修改修改菜品的价格，数量
    public void modifyDishInfo(String uid) {
        System.out.println("打印所有菜品信息。。。");
        showDishes(uid);
        System.out.println("请输入您要查询的菜品ID：");
        String id = sc.next();
        vegetableList dish = d.findByID(id);

        if (dish == null) {
            System.out.println("没有找到当前id的菜品哦亲");
        } else {
            System.out.println("当前菜品为：" + dish);
            while (true) {

                System.out.println("请输入修改后的信息：ps.格式：菜品ID/菜品名/菜品类型/单价/总数量");
                String dID = sc.next();
                String[] info = toString().split("/");

                if (info.length < 5) {
                    System.out.println("输入失败！请重新输入！");
                    continue;
                } else {
                    LocalDate dtime = LocalDate.now();//获取现在

                    dish.setDame(info[1]);
                    dish.setdType(info[2]);
                    dish.setdPrice(Double.parseDouble(info[3]));
                    dish.setdNum(Integer.parseInt(info[4]));

                    /*vegetableList od = new vegetableList(info[0], info[1], info[2], Double.parseDouble(info[3]), Integer.parseInt(info[4]));
                    d.insert(od);*/
                    System.out.println("修改菜品成功！");
                    System.out.println("修改后信息：" + dish);
                    break;
                }
            }
        }
    }
}

